Glue Code for Named Indirect Calls
If the routine call is referenced indirectly by name, the linker generates glue code in the calling fragment and directs the compiler-generated branch to this code. If the linker finds that a call is local (that is, not cross-fragment), it replaces the GPR2 restore instruction with a NOP instruction.The glue code takes the following steps to switch the direct data areas and execute the actual called routine:
Upon return, control passes directly to the caller (not the glue code) which restores the saved value of GPR2.
- Loads the pointer for the transition vector into GPR12.
- Saves the current value of GPR2.
- Loads the next 4 bytes of the transition vector into GPR2 (effectively switching the direct data area).
- Jumps to the start of the actual routine.
Listing 2-1 shows some sample glue code.
Listing 2-1 Glue code for a cross-fragment call
bl moo_glue ; call the cross-fragment glue lwz R2, R2_save_offs(SP); restore the caller's base pointer ... moo_glue: lwz R12, tvect_of_moo(R2); get pointer to moo's transition ; vector stw R2, R2_save_offs(SP); save the caller's base pointer lwz R0, 0(R12) ; get moo's entry point lwz R2, 4(R12) ; load moo's base pointer mtctr R0 ; move entry point to Count Register bctr ; and jump to moo
- Note
- The linker generates custom glue for each routine since the glue code contains the direct data area offset of the routine's transition vector.
![]()